<template>
  <div id="topSearch">
    <h1 class="con-right-title">
      自动评论库管理
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="内容等级" prop="level">
          <el-select v-model="formInline.level" clearable placeholder="">
            <el-option
              v-for="item in levelList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属学院" prop="collegeId">
          <el-select v-model="formInline.collegeId" clearable placeholder="">
            <el-option
              v-for="item in belongCollegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容类型" prop="type">
          <el-select v-model="formInline.type" clearable placeholder="">
            <el-option
              v-for="item in typelList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属频道" prop="topicType">
          <el-select v-model="formInline.topicType" clearable placeholder="">
            <el-option
              v-for="item in channelList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 输入搜索部分 -->
        <el-form-item label="内容" prop="searchContent">
          <el-input
            clearable
            v-model="formInline.searchContent"
            placeholder="请输入评论内容搜索"
            size="small"
            class="numberInput"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'TopSearch',
  msg: '评论库管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          level: '', // 等级,默认所有
          type: '', // 类型,默认所有
          collegeId: '', // 所属学院,默认所有
          topicType: '', //所属频道
          searchContent: '' // 搜索框内容
        }
      }
    }
  },
  data() {
    return {
      // 等级列表
      levelList: [{ dictLabel: '所有', dictValue: '' }],
      // 所属学院列表
      belongCollegeList: [{ dictLabel: '全部', dictValue: '' }],
      // 类型列表
      typelList: [{ dictLabel: '所有', dictValue: '' }],
      channelList: [{ dictLabel: '所有', dictValue: '' }],

      rules: {
        level: {},
        type: {},
        collegeId: {},
        searchContent: {}
      }
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    // auto_topic_type
    // 获取筛选条件
    async getStatusList() {
      // 获取评论库筛选条件-等级
      let data = await sysNormalDisable('auto_comment_grade', 'autoLevelType')
      this.levelList = this.levelList.concat(data)
      // 获取评论库筛选条件-频道
      let data3 = await sysNormalDisable('auto_topic_type', 'topicType')
      this.channelList = this.channelList.concat(data3)
      // 获取评论库筛选条件-内容类型
      let data1 = await sysNormalDisable('sys_task_type', 'autoContentType')
      this.typelList = this.typelList.concat(data1)
      // 获取评论库筛选条件-学院
      let data2 = await sysNormalDisable('sys_share_college', 'autoCollegeType')
      this.belongCollegeList = this.belongCollegeList.concat(data2)
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
#topSearch {
  .numberInput {
    width: 200px;
  }
}
</style>
